-- stop_action
-- create by panyl
-- 时间停止，停止一切行为

return {
    apply = function(prop, baseValue)
        -- 提升的值
        return prop[3];
    end,

    clear = function(target, prop)
        if target.type == OBJECT_TYPE_USER then
            -- 判断流浪者帐篷格子
            -- 如果是在boss层的话，去它自己的模块拿去数据
            local tentPos;
            if DungeonBossM.isInBossLayer() then
                tentPos = BossTentM.getTentPosList();
            else
                local tentGrid = DungeonTentM.findTentGrid();
                if not tentGrid then
                    return;
                end

                if not tentGrid:isOpened() then
                    return;
                end

                tentPos = tentGrid:getPos();
            end

            -- 抛出事件
            EventMgr.fire(event.GRID_PLAY_ACTION, { ["pos"] = tentPos, });

        elseif target.type == OBJECT_TYPE_MONSTER or target.type == OBJECT_TYPE_GHOST_SHIP then
            -- 怪物/幽灵船怪
            local pos = target:getOwner();
            if target.type == OBJECT_TYPE_GHOST_SHIP then
                pos = target:getPos();
            end
            -- 怪物清除了“时间停止”事件
            EventMgr.fire(event.GRID_LOCK_STATE, {["pos"] = pos, });

            if #PropM.fetchProps(target, "stop_action") <= 0 then
                -- 抛出事件显示待机动画
                EventMgr.fire(event.GRID_PLAY_ACTION, {["pos"] = pos, });
                -- 消除
                target.dbase:delete("isPause");
            end
        end
    end,

    record = function(target, prop, path)
        if DungeonM.getState() ~= DUNGEON_GAMING then 
            return false;
        end
        
        if target.type == OBJECT_TYPE_USER then
            -- 判断流浪者帐篷格子
            -- 如果是在boss层的话，去它自己的模块拿去数据
            local tentPos;
            if DungeonBossM.isInBossLayer() then
                tentPos = BossTentM.getTentPosList();
            else
                local tentGrid = DungeonTentM.findTentGrid();
                if not tentGrid then
                    return;
                end

                if not tentGrid:isOpened() then
                    return;
                end

                tentPos = tentGrid:getPos();
            end

            -- 抛出事件
            EventMgr.fire(event.GRID_LOCK_ACTION, { ["pos"] = tentPos, });

        elseif target.type == OBJECT_TYPE_MONSTER or target.type == OBJECT_TYPE_GHOST_SHIP then
            -- 怪物/幽灵船怪
            -- 设置需要停止动画
            target.dbase:set("isPause", true);

            -- 抛出事件暂停
            local pos = target:getOwner();
            if target.type == OBJECT_TYPE_GHOST_SHIP then
                pos = target:getPos();
            end
            EventMgr.fire(event.GRID_LOCK_ACTION, {["pos"] = pos, });
        end
        return false;
    end
};
